//ZUI模态窗
function ZuiModal(opt)
{
    if( ! opt.hasOwnProperty("ajax")){ opt.ajax = "ajax"; }
    if( ! opt.hasOwnProperty("url")){ opt.url = ""; }
    if( ! opt.hasOwnProperty("title")){ opt.title = "窗口"; }
    if( ! opt.hasOwnProperty("icon")){ opt.icon = ""; }
    //console.log(opt);
    (new $.zui.ModalTrigger(opt)).show();
}

//关闭ZUI的模态窗
function closeZuiModal()
{
    $('#triggerModal').remove();
    $('.modal-backdrop').remove();
}

//input只能输入数字 ex : onkeyup="onlyNum(this, this.value)"
function onlyNum(obj, v)
{
    obj.value = v.replace(/\D/g, '');
}

//input只能输入数字 ex : onkeyup="onlyNum(this, this.value)"
function numDot(obj, v)
{
    if(isNaN(v)){
        obj.value = '';
    }
}

//是否Email
function isEmail(str)
{
    var reg = /^([a-zA-Z0-9|\_|\-|\.])+@([a-zA-Z0-9_-])+((\.[a-zA-Z0-9_-]{2,4}){1,2})$/;
    return reg.test(str);
}

//手机号码
function isMobile(v)
{
    if((/^1[345678]+\d{9}$/.test(v))){
        return true;
    }else{
        return false;
    }
}

function onlyMobile(obj, v)
{
    if( ! isMobile(v)){ $(obj).val(''); }
}

function isIDCard(card)
{
    //身份证号码为15位或者18位，15位时全为数字，18位前17位为数字，最后一位是校验位，可能为数字或字符X
    var reg = /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/;
    return reg.test(card);
}

function onlyIDCard(obj, v)
{
    if( ! isIDCard(v)){ $(obj).val(''); }
}

//全选
function checkAll(obj, name){
    var flag = false;
    if(obj.checked == true){flag = true;}
    checkAllCheckBox(name, flag);
}

//全选
function checkAllCheckBox(name, flag)
{
    name = $.trim(name); if(name == ''){ return; }
    if(flag!== true && flag!==false){ flag = false; }
    var names = document.getElementsByName(name);
    var len = names.length;
    for(var i=0; i<len; i++){
        names[i].checked = flag;
    }
}

//是否安装flash
function checkFlash()
{
    var hasFlash = false;
    try{
        hasFlash = Boolean(new ActiveXObject('ShockwaveFlash.ShockwaveFlash'));
    }catch(exception){
        hasFlash = ('undefined' != typeof navigator.mimeTypes['application/x-shockwave-flash']);
    }
    return hasFlash;
}

//提交表单
function submitFormByID(id)
{
    id = $.trim(id);
    if(id == ''){ return false; }
    $('#'+id).submit();
}

function backStep(n)
{
    n = parseInt(n);
    if(isNaN(n)){ n = -1; }
    window.history.go(n);
}

//按钮状态
function buttonStatus(id, st, wz)
{
    if(st == 'y'){
        $('#'+id).val(wz).addClass('disabled');
    }else{
        $('#'+id).val(wz).removeClass('disabled');
    }
}

function rl()
{
    window.location.reload(true);
}

function isIEBrowser()
{
    var userAgent = navigator.userAgent;
    var isIE = userAgent.indexOf("compatible") > -1 && userAgent.indexOf("MSIE") > -1;
    if(isIE)
    {
        var IE5 = false;
        var IE55 = false;
        var IE6 = false;
        var IE7 = false;
        var IE8 = false;
        var reIE = new RegExp("MSIE (\\d+\\.\\d+);");
        reIE.test(userAgent);
        var fIEVersion = parseFloat(RegExp["$1"]);
        IE55 = fIEVersion == 5.5;
        IE6 = fIEVersion == 6.0;
        IE7 = fIEVersion == 7.0;
        IE8 = fIEVersion == 8.0;
        if (IE55) {
            return 5;
        }
        if (IE6) {
            return 6;
        }
        if (IE7) {
            return 7;
        }
        if (IE8) {
            return 8;
        }
        return 9;
    }else{
        return 0;
    }
}

//JS 创建 post 表单并提交
function doPost(url, params)
{
    var temp = document.createElement("form");
    temp.action = url;
    temp.method = "post";
    temp.style.display = "none";
    for(var x in params){
        var opt = document.createElement("input");
        opt.name = x;
        opt.value = params[x];
        temp.appendChild(opt);
    }
    document.body.appendChild(temp);
    temp.submit();
    return temp;
}

function isRadioChecked(n)
{
    var obj = document.getElementsByName(n);
    var flag = false;
    for(var i=0,j=obj.length; i<j; i++){
        if(obj[i].checked){
            flag = true;
            break;
        }
    }
    return flag;
}

//控制main_iframe前进、后退、刷新
function goStep(key){
    if(!key){key = 'b';}
    var obj = window.top.frames.main_iframe;
    switch(key){
        case 'b' :
            obj.history.back();
            break;
        case 'f' :
            obj.history.forward();
            break;
        case 'r' :
            obj.location.reload();
            break;
        default :
            obj.location.reload();
    }
}

//切换
function goTab(n, nn)
{
    $('.tc_'+n).hide();
    $('#tc_'+n+'_'+nn).show();
    $('.tt_'+n).removeClass('current');
    $('#tt_'+n+'_'+nn).addClass('current');
}